ALMaSS  1.0
The Animal, Landscape and Man Simulation System
k_factors Class Reference

Class for calculating k-factors. More...

#include <Partridge_All.h>

Public Member Functions

void calcreal_1 ()
 
void calcreal_2 ()
 
void calcreal_3 ()
 
void calcDickPottsk ()
 
void Output_kfactors ()
 
void CreateInfoDatabaseFile ()
 
 k_factors ()
 
 ~k_factors ()
 

Public Attributes

population_attributesm_ThisYear
 
population_attributesm_LastYear
 

Protected Member Functions

void reset ()
 
void DumpInfoDatabase1 (int, int, double)
 
void DumpInfoDatabase ()
 

Protected Attributes

FILE * kfactorsfile
 
double m_rk1
 
double m_rk2
 
double m_rk3
 
double m_rk4
 
double m_rk5
 
double m_rk6
 
double m_dpk1
 
double m_dpk2
 
double m_dpk3
 
double m_dpk4
 
double m_dpk5
 

Detailed Description

Class for calculating k-factors.

Constructor & Destructor Documentation

◆ k_factors()

k_factors::k_factors ( )
2859 {
2860  kfactorsfile = fopen("k_factors_output.txt", "w" );
2861  if ( !kfactorsfile ) {
2862  g_msg->Warn( "k_factors::k_factors()","Cannot open k_factors_output.txt" );
2863  exit( 1 );
2864  }
2867  reset();
2868 }
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
population_attributes * m_LastYear
Definition: Partridge_All.h:252
void reset()
Definition: Partridge_All.cpp:2978
population_attributes * m_ThisYear
Definition: Partridge_All.h:251
FILE * kfactorsfile
Definition: Partridge_All.h:243
Definition: Partridge_All.h:45
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41

References g_msg, kfactorsfile, m_LastYear, m_ThisYear, reset(), and MapErrorMsg::Warn().

◆ ~k_factors()

k_factors::~k_factors ( )
2872 {
2873  fclose( kfactorsfile );
2874  delete m_ThisYear;
2875  delete m_LastYear;
2876 }

References kfactorsfile, m_LastYear, and m_ThisYear.

Member Function Documentation

◆ calcDickPottsk()

void k_factors::calcDickPottsk ( )
3027 {
3028  // Dick makes some assumptions such it is assumed old males seen on 1st sept
3029  // is the same number as the number of pairs in Spring.
3030  // He also uses a calculation for the number of chicks hatched based on
3031  // the geometric mean of brood size on 1st September.
3032  // k2 assumes the differences between old males and old females is female on nest mortality
3033 
3034  // Requires the following values to be set before entry:
3035  // 1) GeoMean brood size, 1st sept.
3036  // 2) No. old males
3037  // 3) No. old females
3038  // 4) No. Males Sept
3039  // 5) No. Females Sept
3040  // 6) No. Females Sept of last year
3041  // 7) No. chicks at 1st Sept.
3042 
3043  // Calculate HatchedChicks
3044  double HatchedChicks;
3045  double CSR;
3046  if ( m_LastYear->m_geomeanBroodSize < 10.0 ) CSR = 0.03665 * ( pow( ( double )m_LastYear->m_geomeanBroodSize, ( double )1.293 ) );
3047  else
3048  CSR = m_LastYear->m_geomeanBroodSize / 13.84;
3049  if ( CSR > 0 ) HatchedChicks = m_LastYear->m_NoChicksSept / CSR;
3050  else
3051  HatchedChicks = 0;
3052  //
3053  double Broods = HatchedChicks / 13.8; // 13.8 is the mean brood size used by Dick, but we use 14
3054  // k2 is assuming old males is the same as pairs
3055  m_dpk2 = log10( ( double )( 1 + m_LastYear->m_NoOldMales ) / ( double )( 1 + m_LastYear->m_NoOldFemales ) );
3056  // k1 assumes old males in sept is the same as no. pairs in spring
3057  m_dpk1 = log10( ( double )( 1 + m_LastYear->m_NoOldMales ) / ( 1 + Broods ) ) - m_dpk2;
3058  // k3 contains a calculated number of chicks at six weeks based on the number
3059  // of chicks in Sept and brood size.
3060  m_dpk3 = log10( ( double )( 1 + HatchedChicks ) / ( double )( 1 + m_LastYear->m_NoChicksSept ) );
3061  // k4 Shooting numbers recorded so should be solid
3062  double NoBirdsAfterShoot = ( ( m_LastYear->m_NoMalesSept + m_LastYear->m_NoFemalesSept ) - m_LastYear->m_NoShotBirds );
3063  m_dpk4 = log10( ( double )( ( 1 + m_LastYear->m_NoMalesSept + m_LastYear->m_NoFemalesSept ) ) / ( double )( 1 + NoBirdsAfterShoot ) );
3064  // k5 - tricky one. Assumes 1:1 sex ratio. Assumes that the number of females
3065  // at the end of year 1 is equal to the number of breeding males and this is
3066  // equal to the number of old males in year 2. Hence the difference is the number
3067  // of birds that die of everything else except hen mortality.
3068  m_dpk5 = log10( ( double )( 1 + (m_LastYear->m_NoFemalesSept - m_LastYear->m_NoShotFemales)) / ( double )( 1 + m_ThisYear->m_NoOldMales ) );
3069  DumpInfoDatabase1( ( int )Broods, ( int )HatchedChicks, CSR );
3070 
3072  //m_ThisYear->reset(); // ***CJT*** 6/7/2010 removed because otherwise our counts are destroyed - why was this here?
3073 }
double m_dpk2
Definition: Partridge_All.h:245
double m_dpk4
Definition: Partridge_All.h:245
double m_dpk3
Definition: Partridge_All.h:245
double m_dpk1
Definition: Partridge_All.h:245
double m_dpk5
Definition: Partridge_All.h:245
void DumpInfoDatabase1(int, int, double)
Definition: Partridge_All.cpp:3076
int m_NoChicksSept
Definition: Partridge_All.h:55
int m_NoMalesSept
Definition: Partridge_All.h:53
int m_NoShotFemales
Definition: Partridge_All.h:57
int m_NoFemalesSept
Definition: Partridge_All.h:54
int m_NoOldFemales
Definition: Partridge_All.h:59
int m_NoOldMales
Definition: Partridge_All.h:58
void copyself(population_attributes *a_population_attributes)
Definition: Partridge_All.cpp:2904
double m_geomeanBroodSize
Definition: Partridge_All.h:60
int m_NoShotBirds
Definition: Partridge_All.h:56

References population_attributes::copyself(), DumpInfoDatabase1(), m_dpk1, m_dpk2, m_dpk3, m_dpk4, m_dpk5, population_attributes::m_geomeanBroodSize, m_LastYear, population_attributes::m_NoChicksSept, population_attributes::m_NoFemalesSept, population_attributes::m_NoMalesSept, population_attributes::m_NoOldFemales, population_attributes::m_NoOldMales, population_attributes::m_NoShotBirds, population_attributes::m_NoShotFemales, and m_ThisYear.

Referenced by Partridge_Population_Manager::DoFirst().

◆ calcreal_1()

void k_factors::calcreal_1 ( )
2995 {
2996  // These can be calculated on Sept 1st.
2997  double anum = 1 + ( m_ThisYear->m_NoClutches - m_ThisYear->m_NoHensPredated );
2998  m_rk2 = log10( ( 1 + m_ThisYear->m_NoClutches ) / anum );
2999  anum = 1 + m_ThisYear->m_NoClutchesHatched;
3000  m_rk1 = log10( ( 1 + m_ThisYear->m_NoClutches ) / anum ) - m_rk2;
3001  anum = 1 + m_ThisYear->m_NoChicksSept;
3002  m_rk3 = log10( ( 1 + m_ThisYear->m_NoChicksHatched ) / anum );
3003 }
double m_rk1
Definition: Partridge_All.h:244
double m_rk3
Definition: Partridge_All.h:244
double m_rk2
Definition: Partridge_All.h:244
int m_NoClutches
Definition: Partridge_All.h:50
int m_NoHensPredated
Definition: Partridge_All.h:63
int m_NoClutchesHatched
Definition: Partridge_All.h:78
int m_NoChicksHatched
Definition: Partridge_All.h:51

References population_attributes::m_NoChicksHatched, population_attributes::m_NoChicksSept, population_attributes::m_NoClutches, population_attributes::m_NoClutchesHatched, population_attributes::m_NoHensPredated, m_rk1, m_rk2, m_rk3, and m_ThisYear.

Referenced by Partridge_Population_Manager::DoFirst().

◆ calcreal_2()

void k_factors::calcreal_2 ( )
3007 {
3008  // This can only be calculated after shooting
3009  double NoBirdsAfterShoot = ( ( m_ThisYear->m_NoMalesSept + m_ThisYear->m_NoFemalesSept ) - m_ThisYear->m_NoShotBirds );
3010  double anum = 1 + NoBirdsAfterShoot;
3011  m_rk4 = log10( ( 1 + m_ThisYear->m_NoMalesSept + m_ThisYear->m_NoFemalesSept ) / anum );
3012 }
double m_rk4
Definition: Partridge_All.h:244

References population_attributes::m_NoFemalesSept, population_attributes::m_NoMalesSept, population_attributes::m_NoShotBirds, m_rk4, and m_ThisYear.

Referenced by Partridge_Population_Manager::DoFirst().

◆ calcreal_3()

void k_factors::calcreal_3 ( )
3016 {
3017  // K5 is the number of males and females in Sept/those that survive to
3018  // breeding time. This means k5 can only be calculated in April.
3019  double anum = 1 + m_ThisYear->m_NoFemalesSept - m_ThisYear->m_NoShotBirds / 2;
3020  m_rk5 = log10( anum / ( double )( 1 + m_ThisYear->m_NoFemalesApril ) );
3022  m_rk6 = log10( anum / ( double )( 1 + m_ThisYear->m_NoBirdsApril ) );
3023 }
double m_rk6
Definition: Partridge_All.h:244
double m_rk5
Definition: Partridge_All.h:244
int m_NoFemalesApril
Definition: Partridge_All.h:65
int m_NoBirdsApril
Definition: Partridge_All.h:68

References population_attributes::m_NoBirdsApril, population_attributes::m_NoFemalesApril, population_attributes::m_NoFemalesSept, population_attributes::m_NoMalesSept, population_attributes::m_NoShotBirds, m_rk5, m_rk6, and m_ThisYear.

Referenced by Partridge_Population_Manager::DoFirst().

◆ CreateInfoDatabaseFile()

void k_factors::CreateInfoDatabaseFile ( )

Open a k-factor output file.

3146 {
3147  FILE * idb = fopen("k_facInfoBase.txt", "w" );
3148  if (!idb) {
3149  g_msg->Warn("k_factors::CreateInfoDatabaseFile","Cannot open k_facInfoBase.txt" );
3150  exit( 1 );
3151  }
3152  fclose( idb );
3153 }

References g_msg, and MapErrorMsg::Warn().

Referenced by Partridge_Population_Manager::Init().

◆ DumpInfoDatabase()

void k_factors::DumpInfoDatabase ( )
protected
3089 {
3090  FILE * idb = fopen("k_facInfoBase.txt", "a" );
3091  if (!idb) {
3092  g_msg->Warn( "k_factors::DumpInfoDatabase","Cannot open k_facInfoBase.txt" );
3093  exit( 1 );
3094  }
3095  fprintf( idb, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%g\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
3102 
3103  /*
3104  1m_NoClutches,
3105  2m_NoClutchesHatched,
3106  3m_NoHensPredated,
3107  4m_NoChicksSixWeeks,
3108  5m_NoChicksSept,
3109  6m_NoMalesSept,
3110  7m_NoFemalesSept,
3111  8m_NoDeadFemales,
3112  9m_NoDeadMales,
3113  10m_NoShotBirds,
3114  11m_NoChicksHatched,
3115  12m_NoOldMales,
3116  13m_NoOldFemales,
3117  14m_geomeanBroodSize,
3118  15m_NoClutchesPredated,
3119  16m_NoFemalesApril,
3120  17m_NoTerritorialFemalesApril,
3121  18m_NoDeadChicks,
3122  19m_NoDeadClutches,
3123  20m_NoClutchesReplacements,
3124  21m_NoAgDeadClutches,
3125  22m_NoPairsApril,
3126  23m_NoMalesApril,
3127  24m_NoTerritorialFemalesMay,
3128  25m_NoNonTerritorialFemalesMay
3129  26m_NoMalesDec
3130  27m_NoFemalesDec
3131  28m_NoChick1sAug,
3132  29m_NoChick2sAug,
3133  30m_NoMalesAug,
3134  31m_NoFemsAug
3135  32m_NoStarvedChicks
3136  */
3137 
3138  fclose( idb );
3139 }
int m_NoMalesApril
Definition: Partridge_All.h:66
int m_NoDeadClutches
Definition: Partridge_All.h:71
int m_NoChick1sAug
Definition: Partridge_All.h:80
int m_NoChick2sAug
Definition: Partridge_All.h:81
int m_NoFemsAug
Definition: Partridge_All.h:83
int m_NoDeadFemales
Definition: Partridge_All.h:74
int m_NoDeadChicks
Definition: Partridge_All.h:73
int m_NoMalesDec
Definition: Partridge_All.h:69
int m_NoTerritorialFemalesApril
Definition: Partridge_All.h:67
int m_NoFemalesDec
Definition: Partridge_All.h:70
int m_NoNonTerritorialFemalesMay
Definition: Partridge_All.h:77
int m_NoAgDeadClutches
Definition: Partridge_All.h:72
int m_NoTerritorialFemalesMay
Definition: Partridge_All.h:76
int m_NoChicksSixWeeks
Definition: Partridge_All.h:52
int m_NoStarvedChicks
Definition: Partridge_All.h:84
int m_NoClutchesReplacements
Definition: Partridge_All.h:61
int m_NoDeadMales
Definition: Partridge_All.h:75
int m_NoMalesAug
Definition: Partridge_All.h:82
int m_NoPairsApril
Definition: Partridge_All.h:64
int m_NoClutchesPredated
Definition: Partridge_All.h:62

References g_msg, population_attributes::m_geomeanBroodSize, population_attributes::m_NoAgDeadClutches, population_attributes::m_NoChick1sAug, population_attributes::m_NoChick2sAug, population_attributes::m_NoChicksHatched, population_attributes::m_NoChicksSept, population_attributes::m_NoChicksSixWeeks, population_attributes::m_NoClutches, population_attributes::m_NoClutchesHatched, population_attributes::m_NoClutchesPredated, population_attributes::m_NoClutchesReplacements, population_attributes::m_NoDeadChicks, population_attributes::m_NoDeadClutches, population_attributes::m_NoDeadFemales, population_attributes::m_NoDeadMales, population_attributes::m_NoFemalesApril, population_attributes::m_NoFemalesDec, population_attributes::m_NoFemalesSept, population_attributes::m_NoFemsAug, population_attributes::m_NoHensPredated, population_attributes::m_NoMalesApril, population_attributes::m_NoMalesAug, population_attributes::m_NoMalesDec, population_attributes::m_NoMalesSept, population_attributes::m_NoNonTerritorialFemalesMay, population_attributes::m_NoOldFemales, population_attributes::m_NoOldMales, population_attributes::m_NoPairsApril, population_attributes::m_NoShotBirds, population_attributes::m_NoShotFemales, population_attributes::m_NoStarvedChicks, population_attributes::m_NoTerritorialFemalesApril, population_attributes::m_NoTerritorialFemalesMay, m_ThisYear, and MapErrorMsg::Warn().

Referenced by Output_kfactors().

◆ DumpInfoDatabase1()

void k_factors::DumpInfoDatabase1 ( int  Broods,
int  HC,
double  CSR 
)
protected
3077 {
3078  FILE * idb = fopen("k_facInfoBase.txt", "a" );
3079  if ( !idb ) {
3080  g_msg->Warn( "k_factors::DumpInfoDatabase1","Cannot open k_facInfoBase.txt" );
3081  exit( 1 );
3082  }
3083  fprintf( idb, "%d\t%d\t%d\t%g\t", HC, Broods, m_ThisYear->m_NoOldMales, CSR );
3084  fclose( idb );
3085 }

References g_msg, population_attributes::m_NoOldMales, m_ThisYear, and MapErrorMsg::Warn().

Referenced by calcDickPottsk().

◆ Output_kfactors()

void k_factors::Output_kfactors ( )
2894 {
2895  //calcDickPottsk();
2896  fprintf( kfactorsfile, "%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n", m_rk1, m_rk2, m_rk3, m_rk4, m_rk5, m_rk6, m_dpk1,
2897  m_dpk2, m_dpk3, m_dpk4, m_dpk5 );
2898  fflush( kfactorsfile );
2899  DumpInfoDatabase();
2900  reset();
2901 }
void DumpInfoDatabase()
Definition: Partridge_All.cpp:3088

References DumpInfoDatabase(), kfactorsfile, m_dpk1, m_dpk2, m_dpk3, m_dpk4, m_dpk5, m_rk1, m_rk2, m_rk3, m_rk4, m_rk5, m_rk6, and reset().

Referenced by Partridge_Population_Manager::DoFirst().

◆ reset()

void k_factors::reset ( )
protected
2979 {
2980  m_ThisYear-> reset();
2981  m_rk1 = 0;
2982  m_rk2 = 0;
2983  m_rk3 = 0;
2984  m_rk4 = 0;
2985  m_rk5 = 0;
2986  m_dpk1 = 0;
2987  m_dpk2 = 0;
2988  m_dpk3 = 0;
2989  m_dpk4 = 0;
2990  m_dpk5 = 0;
2991 
2992 }

References m_dpk1, m_dpk2, m_dpk3, m_dpk4, m_dpk5, m_rk1, m_rk2, m_rk3, m_rk4, m_rk5, and m_ThisYear.

Referenced by k_factors(), and Output_kfactors().

Member Data Documentation

◆ kfactorsfile

FILE* k_factors::kfactorsfile
protected

This class contains the functionality required to make two types of k-factors the first type is the 'real' k-factor, the second is the way Dick Potts calculated his.
Not yet functional/tested - 5thOct2008

Referenced by k_factors(), Output_kfactors(), and ~k_factors().

◆ m_dpk1

double k_factors::m_dpk1
protected

◆ m_dpk2

double k_factors::m_dpk2
protected

◆ m_dpk3

double k_factors::m_dpk3
protected

◆ m_dpk4

double k_factors::m_dpk4
protected

◆ m_dpk5

double k_factors::m_dpk5
protected

◆ m_LastYear

population_attributes* k_factors::m_LastYear

◆ m_rk1

double k_factors::m_rk1
protected

Referenced by calcreal_1(), Output_kfactors(), and reset().

◆ m_rk2

double k_factors::m_rk2
protected

Referenced by calcreal_1(), Output_kfactors(), and reset().

◆ m_rk3

double k_factors::m_rk3
protected

Referenced by calcreal_1(), Output_kfactors(), and reset().

◆ m_rk4

double k_factors::m_rk4
protected

Referenced by calcreal_2(), Output_kfactors(), and reset().

◆ m_rk5

double k_factors::m_rk5
protected

Referenced by calcreal_3(), Output_kfactors(), and reset().

◆ m_rk6

double k_factors::m_rk6
protected

Referenced by calcreal_3(), and Output_kfactors().

◆ m_ThisYear


The documentation for this class was generated from the following files: